package com.zhou.demo.conf;

import com.alibaba.fastjson.JSONObject;
import org.graylog2.syslog4j.Syslog;
import org.graylog2.syslog4j.SyslogConstants;
import org.graylog2.syslog4j.SyslogIF;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class MySyslogClient {
    private static final String HOST = "127.0.0.1";
    private static final int PORT = 514;

    public void generate() {
        SyslogIF syslog = Syslog.getInstance(SyslogConstants.UDP);
        syslog.getConfig().setHost(HOST);
        syslog.getConfig().setPort(PORT);


        try {
            for (int i = 1; i < 3000; i++) {
//            System.out.println(i);
                StringBuffer buffer = new StringBuffer();
                buffer.append("<6>2022-07-19 10:49:00 AS0001 reportType=transFlows;regionCode=362524;ratedFlows=78643200;currentFlows="+i+";freeFlows=78642715;ratedRequests=500;curentRequests=3;freeRequests=497;remarkMsg=req_137_res_485;");
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("message", buffer.toString());
            syslog.log(0, URLDecoder.decode(jsonObject.toString(), "utf-8"));
        }
        } catch (UnsupportedEncodingException e) {
            System.out.println("generate log get exception " + e);
        }
    }

    public static void main(String[] args) {
        new MySyslogClient().generate();
    }
}

